Boolean Values


The AND operator

It is used to connect two Boolean conditions in the WHERE clause of a SELECT statement. When the SQL statement is executed, only those rows that satisfy both conditions are retrieved. The syntax for using AND with two Boolean conditions is shown below.
Éste es usado para conectar dos condiciones Bool en un operador WHERE de un comando SQL. Cuando el comando de SQL se ejecuta, solamente aquellos renglones que satisfagan ambas condiciones serán incluídos como parte del comando. Debajo se muestra la sintaxis típica del operador AND.

SQL
SELECT column_list
FROM tablename
WHERE condition_1 AND condition2;

The OR operator

It is used to connect two Boolean conditions in the WHERE clause of a SELECT statement. The rows that are retrieved are those that satisfy either or both conditions. The syntax for using OR with two Boolean conditions is shown below.
Éste es usado para conectar dos condiciones Bool en un operador WHERE de un comando SQL. Cuando el comando de SQL se ejecuta, solamente aquellos renglones que satisfagan cualquiera o ambas condiciones serán incluídos como parte del comando. Debajo se muestra la sintaxis típica del operador OR.

SQL
SELECT column_list
FROM tablename
WHERE condition_1 OR condition2;

The NOT operator

It is used to specify the column values that are used to exclude the record from display. The AND and the OR may be used to connect two or more conditions. They are binary operators. The NOT acts only on one condition. It is a unary operator. The syntax for using NOT with a WHERE condition is shown below.
Éste es usado para especificar los valores de las columnas que serán usados para excluir los renglones o registros. Los operadores AND y OR son binarios y se usan para conectar dos condiciones. El operador NOT actua en una sola condición. La sintaxis de este comando se muestra debajo.

SQL
SELECT column_list
FROM tablename
WHERE NOT condition;


Tip
The placement of the NOT operator is awkward when reading it in English. It would sound better to place it like this (but it is INCORRECT in SQL):

WHERE zip_code NOT='94500';

However, it is invalid to place the NOT operator immediately adjacent to the equal-to operator (=). If that sequence is desired, it would be better to use the non-equal-to relational operator (<>). The following two conditions are interchangeable and will produce the same output:

WHERE NOT zip_code ='94500';
WHERE zip_code <> '94500';
La forma de usar el operador NOT es un poco extraña cuando se lee en inglés. Se escucharía mejor si se escribiera así: (pero esto es incorrecto en SQL):

WHERE zip_code NOT='94500';

Sin embargo, es inválido colocar el operador NOT inmediatamente antes del operador de igual. Si se desea usar la estructura mostrada es mejor usar el operador de diferente, <>. Las dos siguientes condiciones son equivalentes y producirán los mismos resultados:

WHERE NOT zip_code ='94500';
WHERE zip_code <> '94500';

Tip
SQL is very flexible and allows programmers to use the different operators as shown:

WHERE ZipCode <> '94500';
WHERE ZipCode != '94500'
SQL posee una flexibilidad que permite a los programadores expresar el operador de diferente en la forma que ellos están acostumbrados, como muestra el ejemplo:

WHERE ZipCode <> '94500';
WHERE ZipCode != '94500'

Problem 1
city_bank > Write an SQL query to list the account_id's of all the accounts that are not of type Checking.
Escriba un comando SQL para listar todos los números de identificación de cuenta que no son de cheques.

cb_account

Problem 2
city_bank > Write an SQL query to list the client name of all the clients who do not have a checking account.
Escriba un comando SQL para listar los nombres de los clientes que no tienen una cuenta de cheques.

cb_clientname

Problem 3
city_bank > Write an SQL query to list the account_id's of all the accounts that are not of type Savings neither they are in the Bellavista branch.
Escriba un comando SQL para listar los números de identificación de cuentas de aquellas cuentas que no son de Ahorros y que no pertenecen a la sucursal Bellavista.

cb_bellavista

Hint
The NOT is a unary operator and must be repeated with each condition unless parentheses are used.
El operador NOT requiere solo un argumento y puede usarse en forma repetida si varias condiciones son requeridas (a menos que se usen paréntesis.)

D'Morgan Law

When using Boolean operators, it is helpful to examine some equivalent ways of expressing the same conditions. These conditions are also known as the D'Morgan's Laws (see figure below).

NOT (p AND q) same as (NOT p) OR (NOT q)
NOT (p OR q) same as (NOT p) AND (NOT q)
NOT (NOT p) same as p
Al usar los operadores Bool, es posible simplificar las expresiones lógicas usando las leyes D'Morgan que se muestran arriba (vea la figura de abajo).

DeMorgan

Problem 4
city_bank > Write an SQL query to list the account_id of all the accounts that are not of type Savings neither they are in the Bellavista branch. Use D'Morgan's Laws to reduce the query complexity. Your result must include only one NOT operator (or only one !=).
Escriba un comando SQL para listar los números de identificación de cuentas de aquellas cuentas que no son de Ahorros y que no pertenecen a la sucursal Bellavista. Use las leyes de D'Morgan para simplicar su comando SQL, ya que su consulta puede incluir solamente un operador NOT (o solo un !=).

cb_morgan

Problem 5
city_bank > Write an SQL query to list the client name, account_id of all the accounts that are not of type Savings neither they are in the Bellavista branch.
Escriba un comando SQL para listar los números de identificación de cuentas y el nombre del cliente de aquellas cuentas que no son de Ahorros y que no pertenecen a la sucursal Bellavista.

cb_branchmor

Problem 6
ford > (a) Write an SQL query to list the names of all the stores in the store table which have Excellent sales and are in the zip code 94007. (b) Repeat the same query using one NOT(...) and D'Morgan's Laws.
(a) Escribir una consulta SQL para listar el nombre de las tiendas que tienen ventas Excelentes en el código postal 94007. (b) Repita la misma consulta usando un NOT(...) y las Leyes de D'Morgan.

ford_excell

Problem 7
ford > Write an SQL query to list the names of all the stores and their addresses in the store table which have Excellent sales and are in California.
Escribir una consulta SQL para listar el nombre de las tiendas y su dirección que tienen ventas Excelentes en el estado de California.

ford_ca

Problem 8
ford > Write an SQL query to list the names of all the stores and their addresses in the store table which have Good sales, are in Hoboken, and their zip code is 94006.
Escribir una consulta SQL para listar los nombres de las tiendas y su dirección de la tabla store que tienen buenas ventas, están en Hoboken, y el código postal es 94006.

ford_hoboken

Problem 9
ford > Write an SQL query to list the names of all the stores and their zip codes in the store table which have Excellent or Good sales.
Escribir una consulta SQL para listar el nombre de todas las tiendas que tienen ventas excelentes o buenas como se muestra.

ford_good

Problem 10
ford > Write an SQL query to list the names, zip codes, sales of all the stores in the Store table which have Excellent sales, or are at zip code 94006, or are in NJ.
Escribir una consulta SQL para listar el nombre, código postal, ventas de todas las tiendas que tienen ventas excelentes, o están en el código postal 94006 o que están en New Jersey.

ford_nj

Problem 11
ford > Write an SQL query to list the names, zip codes, sales of all the stores in the store table which are not in the 94006 zip code neither have Excellent sales.
Escribir una consulta SQL para listar el nombre, código postal, ventas de todas las tiendas que no están en el código postal 94006 y que no tienen ventas excelentes.

ford_noExc_nozip

Compound Conditions

Order of Precedence
  • ( ) → Evaluate first
  • NOT → Evaluate second
  • AND → Evaluate third
  • OR → Evaluate last

Orden de Precedencia
  • ( ) → Se evalua primero
  • NOT → Se evalua segundo
  • AND → Se evaluar tercero
  • OR → Se evalua al último

Problem 12
ford > Write an SQL query to list the names, zip codes, and sales of all the stores in the store table which have Excellent sales from the 94007 zip to the 94345 zip code.
Escribir una consulta SQL para listar el nombre, código postal y tipo de ventas de las tiendas que tienen ventas excelentes desde los códigos postales del 94007 al 94345.

ford_zips

Problem 13
ford > Write an SQL query to list the names, zip codes, and sales of all the stores in the store table except those in zip code 94345 with Excellent sales.
Escribir una consulta SQL para listar el nombre, código postal y tipo de ventas de todas las tiendas excepto aquellas en el código postal 94345 con ventas excelentes.

ford_not

Problem 16
motorola > Write an SQL query to list the names of the employees who know the programming languages C++ or C#.
Escribir una consulta SQL para listar el apellido de los empleados que conocen los lenguajes de programación C++ o C#.

mot_csharp

Problem 17
motorola > Write an SQL query to list the phone numbers of the employees who speak French in the Sales department.
Escribir una consulta SQL para listar los números de teléfono de aquellos empleados que hablan Francés en el departamento de ventas como se muestra.

mot_sales

© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home